package net.cyue.web.easyquery.test.solon;

import net.cyue.util.ResourceUtil;
import net.cyue.web.easyquery.core.EasyQueryApplication;
import net.cyue.web.easyquery.core.EasyQueryApplicationFactory;
import net.cyue.web.easyquery.core.config.ConfigException;
import net.cyue.web.easyquery.core.http.data.PathInfo;
import org.noear.solon.Solon;
import org.noear.solon.SolonApp;
import org.noear.solon.annotation.SolonMain;

import java.io.IOException;

@SolonMain
public class Main {
    public static void main(String[] args) throws ConfigException, IOException {
        SolonApp app = Solon.start(Main.class, args);
        app.enableHttp();
        Main.initEasyQueryApplication(app);
    }

    public static void initEasyQueryApplication(SolonApp solonApp) throws ConfigException, IOException {
        // easy-query
        EasyQueryApplication<SolonApp> easyQueryApplication = EasyQueryApplicationFactory.create(solonApp);
        easyQueryApplication.getContext().registerWebInterface(
            PathInfo
                .builder()
                .apiPath("/api/v1/userinfo")
                .addQueryParameter("id")
                .addQueryParameter("username")
                .build(),
        "select * from user where id = #{id} or username = #{username}"
        );
        easyQueryApplication.runByProperties(ResourceUtil.getResourceAsStream("example.properties"));
    }
}

